package com.example.smartcity.ui.dashboard;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smartcity.R;
import com.example.smartcity.ui.Tools.OkHttpUtils;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;

import java.util.Arrays;
import java.util.stream.Collectors;

public class ViolationInquiry extends AppCompatActivity {
    private Banner banner;
    private AutoCompleteTextView EDCarType;
    private AutoCompleteTextView EDCarNumber;
    private AutoCompleteTextView ETCarEnginerNumber;
    private TextView TVBtnFind;
    private int[] array = new int[]{R.drawable.car1,R.drawable.car2,R.drawable.car3,R.drawable.car4};
    private String[] carType = new String[]{"小型汽车"};
    private String[] carNumber = new String[]{"京Q315G5","京F1Q622","京FS1009","京F0D988"};
    private String[] carEnginerNumber = new String[]{"12345615","12345729","12345630","12345628","12345716","12345623","12345617","12345727"};
    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_violation_inquiry);
        banner = findViewById(R.id.Banner_Guide);
        EDCarType = findViewById(R.id.ED_carType);
        EDCarNumber = findViewById(R.id.ED_CarNumber);
        ETCarEnginerNumber = findViewById(R.id.ET_CarEnginerNumber);
        TVBtnFind = findViewById(R.id.TV_btnFind);
        initView();
    }
    public void setBack(View view){
        this.finish();
    }
    @RequiresApi(api = Build.VERSION_CODES.N)
    public void initView(){
        //自动提示
        load();
        //轮播图
        banner.setAdapter(new BannerImageAdapter<Integer>(Arrays.stream(array).boxed().collect(Collectors.toList())) {
            @Override
            public void onBindView(BannerImageHolder bannerImageHolder, Integer integer, int i, int i1) {
                Glide.with(getBaseContext()).load(integer).into(bannerImageHolder.imageView);
            }
        }).setIndicator(new CircleIndicator(getBaseContext())).start();
        //提交查询数据
        TVBtnFind.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String newUrl = OkHttpUtils.getBaseUrl(getBaseContext())+"/userinfo/illegal/list?pageNum=1&pageSize=10&catType="+EDCarType.getText().toString()+"&engineNumber="+ETCarEnginerNumber.getText().toString() +"&licencePlate="+EDCarNumber.getText().toString();
                Log.d("TAG", "initView: "+newUrl);
                Intent intent = new Intent(ViolationInquiry.this,ViolationList.class);
                intent.putExtra("newUrl",newUrl);
                startActivity(intent);
            }
        });
    }
    //自动提示
    public void load(){
        EDCarType.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,carType));
        EDCarNumber.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,carNumber));
        ETCarEnginerNumber.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,carEnginerNumber));
    }

}